<template>
    <li @mouseenter="changeDisplay">
        <label>
        <input type="checkbox" :checked="done"/>
        <span>{{content}}</span>
        </label>
        <button v-itemDisplay class="btn btn-danger"  ref="btn" :style="{display}">删除</button>
    </li>
</template>

<script>
export default {
    name: "Item",
    props:["id", "done", "content"],
    data() {
        return {
            display: null
        }
    },
    directives: {
        // itemDisplay(el) {
        //     if(el.style.display === "none") {
        //         el.style.display ==="block"
        //     }else {
        //         el.style.display ==="none"
        //     }
        // }
    },
    methods: {
        changeDisplay() {
            // console.log(this,"====="),
            // console.log(this.$refs,"====="),
            // console.log(this.$refs.btn,"=====");
            // console.log(this.$refs.btn.style,"=====")
            // console.log(this.$refs.btn.style.display,"=====")
            if (this.$refs.btn.style.display === 'none') { //尽量不操作原生DOM,遇见是否隐藏，要想到用变量的true，false，采用三元表达式，选择性获取我们想要的值
                this.display = "block";
                this.display = "block";
            }else {
                this.display = "none";
            }
        }
    }
}
</script>

<style>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  float: left;
  cursor: pointer;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>